#!/bin/sh

################################################
# suppose the root mount point is :
# 	/mnt/media
# env var $MDEV -- device name
# env var $ACTION -- hotplug event, remove or add 
################################################

# root mount point
RMPOINT=/mnt/media

case "$1" in
	"add")
		mkdir -p $RMPOINT/$MDEV
		mount /dev/$MDEV $RMPOINT/$MDEV
		echo "$MDEV" > $RMPOINT/$MDEV/.msdev;;
	"remove")
		sync
		# use lazy option to umount device
		# ensure umount ok.
		umount -l $RMPOINT/$MDEV
		rm -rf $RMPOINT/$MDEV
		exit;;
	*)
		echo "device $1 is unknown."
		exit;;
esac

case $MDEV in
	"sda1"|"mmcblk0"|"mmcblk0p1")
		ln -sf $SMPOINT $RMPOINT"1";;
	"sdb1"|"sda2"|"mmcblk1"|"mmcblk0p2")
		ln -sf $SMPOINT $RMPOINT"2";;
	"sdc1"|"sda3"|"mmcblk0p3")
		ln -sf $SMPOINT $RMPOINT"3";;
	"sdd1"|"sda4"|"mmcblk0p4")
		ln -sf $SMPOINT $RMPOINT"4";;
esac


